import Koa from 'koa';
import {ERROR_CODE, Result} from "./utils/result.js";


const app = new Koa();

/*import result from "./utils/result.js";

const {Result, ERROR_CODE} = result;*/


//mysql数据库连接
import './config/mysqlDB.js'
//sqlserver数据库连接
import './config/sqlServerDB.js'

//自动导入在各个模型中定义关联关系,如：一对一，一对多，多对多,不用在每个模型中导入
import './associate/index.js'
//自动导入中间件
import middleware from './middleware/index.js'
middleware(app)
//自动加载路由
import autoImportRouter from './routes/index.js';
autoImportRouter('./src', app);




app.on('error', (err, ctx) => {
  // console.error('server error', err, ctx);
   ctx.body = Result.error(ERROR_CODE, err);
});


export default app;
